import type { ITestItem } from '../test-item/type'
import type { ITestSetter } from './type'
import { createPaperStorageName } from '../test-loader'
import localforage from 'localforage'


export default class TestSetterCloudStorage {
    static setLevel(testItem: ITestItem, level: number): boolean {
        const { id, paperName } = testItem
        const paperItemStore = localforage.createInstance({ name: createPaperStorageName(paperName) })
        testItem.level = level
        paperItemStore.setItem(id, { ...testItem })
        return true
    }

    static setLastTime(testItem: ITestItem): boolean {
        const { id, paperName } = testItem
        const paperItemStore = localforage.createInstance({ name: createPaperStorageName(paperName) })
        testItem.lastTime = Date.now()
        paperItemStore.setItem(id, { ...testItem })
        return true
    }
}

export function createTestSetterCloudStorage(): ITestSetter {
    return TestSetterCloudStorage as ITestSetter
}